//
//  NavigationViewManager+Push.swift
//  SomePasti
//
//  Created by 李永彬 on 2025/10/19.
//

import SwiftUI

protocol TitledView {
    var navigationTitle: String { get }
}

extension NavigationViewManager {
    func pushTitleView<T: View & TitledView>(
        tag: String,
        animated: Bool = true,
        @ViewBuilder content: () -> T
    ) {
        guard let controllerItem = contorllers[tag] else { return }
        let view = content()
        let hostingController = UIHostingController(rootView: view)
        
        // 从协议中获取标题
        hostingController.navigationItem.title = view.navigationTitle
        hostingController.navigationItem.largeTitleDisplayMode = .never
        controllerItem.controller.pushViewController(hostingController, animated: animated)
    }
}
